Map plots

USA Arrests

library(ggplot2)
## Attaching package: 'ggplot2'
## The following object(s) are masked _by_ '.GlobalEnv':
## 
## scale_colour_discrete, scale_fill_discrete
crimes <- data.frame(state = tolower(rownames(USArrests)), USArrests)
library(reshape2)  # for melt
crimesm <- melt(crimes, id = 1)
require(maps)
## Loading required package: maps
states_map <- map_data("state")
ggplot(crimes, aes(map_id = state)) + geom_map(aes(fill = Murder), map = states_map) + 
    expand_limits(x = states_map$long, y = states_map$lat)

plot of chunk maps_arrests

last_plot() + coord_map()

plot of chunk maps_arrests

ggplot(crimesm, aes(map_id = state)) + geom_map(aes(fill = value), map = states_map) + 
    expand_limits(x = states_map$long, y = states_map$lat) + facet_wrap(~variable)

plot of chunk maps_arrests

Use fig.show='hold'

These are the same plots with fig.show='hold' in the options

ggplot(crimes, aes(map_id = state)) + geom_map(aes(fill = Murder), map = states_map) + 
    expand_limits(x = states_map$long, y = states_map$lat)
last_plot() + coord_map()
ggplot(crimesm, aes(map_id = state)) + geom_map(aes(fill = value), map = states_map) + 
    expand_limits(x = states_map$long, y = states_map$lat) + facet_wrap(~variable)

plot of chunk maps_figshow plot of chunk maps_figshow plot of chunk maps_figshow

Author: Jim Hester Created: 2013 Mar 28 02:44:48 PM Last Modified: 2013 Mar 28 03:18:18 PM